package skipass.command;

import skipass.CardStatSystem;
import skipass.container.Card;
import skipass.container.CountCard;
import skipass.container.DayCard;
import skipass.container.TimeCard;


public class CommandChainFactory {

	private static CommandChainFactory instance;
	private CardStatSystem css;
	
	public static synchronized CommandChainFactory getInstance(CardStatSystem css) {
		if (instance == null) {						
			instance = new CommandChainFactory(css);			
		}
		return instance;
	}		
	
	public CommandChainFactory(CardStatSystem css) {
		this.css = css;
	}
	
	public CommandChain createCommandChain(Card card) {
		CommandChain chain = new CommandChain();
		chain.addCommand(new CheckCardExists(card, css));
		chain.addCommand(new CheckBlocked(card, css));		
		chain.addCommand(new CheckWeekDayType(card, css));		
		if(card instanceof CountCard) {
			chain.addCommand(new CheckCount((CountCard) card));
		}
		if(card instanceof DayCard) {			
			chain.addCommand(new CheckDay((DayCard) card, css));		
		}
		if(card instanceof TimeCard) {		
			chain.addCommand(new CheckTime((TimeCard) card, css));		
		}
		return chain;		
	}
}